package com.imooc.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * 测试Controller
 * @author gcq
 * @Create 2022-01-02
 */
@ApiIgnore // 忽略
@RestController
@RequestMapping("/hello")
public class HelloController {

    /**
     * 要整合日志就必须清除掉项目原本自带的日志
     * 清楚自带的日志 SpringBoot
     *
     *
     * service日志 根据service执行时间长久
     */
    final static Logger logger = LoggerFactory.getLogger(HelloController.class);
    @GetMapping
    public String hello()
    {
        logger.info("日志");
        return "hello";
    }


    /**
     * Spring Session
     * 将Session放到redis中进行管理
     *
     * 缺点：
     * 耦合度过高，不利于其他项目扩展
     * 如果单独全是java项目，则推荐使用
     * @param request
     * @return
     */
    @GetMapping("/setSession")
    public Object setSession(HttpServletRequest request) {
        HttpSession session = request.getSession();
        session.setAttribute("userInfo", "new User");
        session.setMaxInactiveInterval(3600);
        Object userInfo = session.getAttribute("userInfo");
        System.out.println(userInfo);
        return "ok";
    }



}